home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE3 / PD / NEWALARM / !NewAlarm / Source / !RunImage (.txt) next >
RISC OS BBC BASIC V Source  |  2001-10-05  |  46KB  |  1,839 lines

  1.  >!RunImage
  2.  "<NewAlarm$Dir>.Source.SHeap"
  3. $+" at line "+
  4. v$="1
  5. 33 (5 Oct 2001)"
  6.  Procedures start here
  7.  n%,m%,now
  8. p$="NewAlarm"
  9. (alarmpathT$="<"+p$+"$Dir>.Templates"
  10. )param1$="":
  11.  for message substitution
  12. param2$=""
  13.  block% 255
  14.  mainind% 1250,timeblock% 36
  15. shutdown%=
  16. :beep%=
  17. count%=0
  18. lib_lastopen%=-1
  19.  initbl% 12
  20. initbl%!0=8
  21. initbl%!4=&502
  22. initbl%!8=&400C1
  23. initbl%!12=0
  24.  "Wimp_Initialise",300,&4B534154,p$,initbl% 
  25.  notfont%
  26. notfont%=(notfont%<350)
  27. initheaps(128,128)
  28. report(
  29. $+" at line "+
  30. quit:
  31. " temp%=
  32. create_anchor("temp")
  33. #Llast%=
  34. create_anchor("last alarm"):
  35.  store data for last alarm triggered
  36. $Fworkblock%=
  37. create_anchor("workblock"):
  38.  for use of sort, later on
  39. "Wimp_OpenTemplate",,alarmpathT$
  40. extend_named_sliding_block(temp%,1600)
  41. extend_named_sliding_block(workblock%,256)
  42. edit%=
  43. loadwindow("edit")
  44. "Font_FindFont",,"Homerton.Bold",12*16,12*16,0,0 
  45.  fonthandle%
  46. *#am%=
  47. fonticon("AM",fonthandle%)
  48. +#pm%=
  49. fonticon("PM",fonthandle%)
  50. info%=
  51. loadwindow("info")
  52. main%=
  53. loadwindow("main")
  54. .!alarms%=
  55. loadwindow("alarms")
  56. /!repeat%=
  57. loadwindow("repeat")
  58. alert%=
  59. loadwindow("alert")
  60. 1 warning%=
  61. loadwindow("warn")
  62. "Wimp_CloseTemplate"
  63. extend_named_sliding_block(temp%,256)
  64. scrap_sliding_block(workblock%)
  65. "MessageTrans_FileInfo",,"<"+p$+"$Dir>.Messages" 
  66.  ,,n%
  67.  message% n%
  68.  mdata% 16
  69. "MessageTrans_OpenFile",mdata%,"<"+p$+"$Dir>.Messages",message%
  70. changetitle(edit%,
  71. message_lookup("ws"))
  72. date%=2
  73. mth%=3
  74. year%=4
  75. day%=5
  76. dayup%=6
  77. daydn%=7
  78. mthup%=8
  79. mthdn%=9
  80. yrup%=10
  81. yrdown%=11
  82. time%=12
  83. m1%=15
  84. hrup%=16
  85. hrdown%=17
  86. minup%=18
  87. mindown%=19
  88. m2%=20
  89. m3%=21
  90. reset%=22
  91. edit_ok%=23
  92. rept%=24
  93. cancel%=25
  94.  repeat
  95. numup%=1
  96. numdn%=2
  97. rept_num%=3
  98. divup%=4
  99. divdn%=5
  100. div%=6
  101. assembler(120)
  102. seticontext(info%,0,p$)
  103. seticontext(info%,1,"'Rough-time' Alarms")
  104. seticontext(info%,2,"
  105.  Harriet Bazley 1999")
  106. seticontext(info%,4,v$)
  107. menus_init
  108. b0anchor_block%=
  109. create_anchor("anchor_block")
  110. c)repeat_time%=
  111. create_anchor("repeat")
  112. create_named_sliding_block(repeat_time%,36)
  113. hour%=timeblock%+&c
  114. minute%=timeblock%+8
  115. dayno%=timeblock%+&10
  116. month%=timeblock%+&14
  117. i=yr%=timeblock%+&18:
  118.  These are pointers into actual block
  119. k4max%=0:
  120.  length of longest line in alarms window
  121. lTwhichinmenu%=0:
  122.  transfers data on which alarm is being edited across Wimp_Polls
  123. "XOS_ReadVarVal","Choices$Write",block%,256,0 
  124.  ,,n%:block%?n%=13
  125.  $block%="" 
  126.  Choicespath$="<"+p$+"$Dir>." 
  127.  Choicespath$=$block%+"."+p$+"."
  128. loadalarms
  129. getparameters(default_rep_type%,default_rep_interval%)
  130. tCrep_type%=default_rep_type%:rep_interval%=default_rep_interval%
  131. "XOS_File",16,Choicespath$+"Position",block%,0 
  132.  (n% 
  133. w/ n%=
  134. windowinfo(alarms%):
  135. openwindow(main%)
  136.  no stored data
  137.  n%=block%+100
  138.  !n%=main%:n%!28=-1
  139. "Wimp_OpenWindow",,n%
  140.  n%=block%
  141. !n%=alarms%:n%!28=-1
  142. "Wimp_OpenWindow",,n%
  143.  reopen windows at stored size & position
  144. "OS_ReadMonotonicTime" 
  145.  start
  146. check_time(
  147.  make sure the window opens with up-to-date time in it
  148. getparameters(
  149.  var1%,
  150.  var2%)
  151.  default values are 1 5 if invalid parameters passed to !RunImage
  152.  p$,param1$,o%,ptr%
  153. var1%=1:var2%=5:
  154.  defaults
  155.  "OS_GetEnv" 
  156. p$,6):
  157.  remove "BASIC" from environment string
  158. ptr%=!temp%
  159. "OS_ReadArgs","quit/a,interval/e/k,value/e/k,autosave/s",p$,ptr%,256
  160.  ptr%!4>0 
  161.  o%=ptr%!4:var1%=o%!1:
  162.  var1%<1 
  163.  var1%>6 
  164.  var1%=1
  165.  ptr%!8>0 
  166.   o%=ptr%!8:var2%=o%!1
  167.  var1%=1 
  168.  var2%=var2%-(var2% 
  169.  var2%<1 
  170.  var2%>255 
  171.  var2%=5
  172. autosave%=ptr%!12
  173. menus_init
  174.  a$,b$,n%
  175. param1$=p$
  176. Dmainmenu%=
  177. makemenu(
  178. message_looksub("menu"),6):
  179.  make main menu
  180. 3recent%=
  181. makemenu(
  182. message_looksub("recent"),2)
  183. param1$=
  184. 12," ")
  185. message_looksub("del")+"|":a$=
  186. 4,a$)
  187. %alarmmenu%=
  188. makemenu(p$+"|"+a$,4)
  189. submenuhandle(mainmenu%,1)+4)=info%
  190. submenuhandle(mainmenu%,5)+4)=recent%
  191. submenuhandle(mainmenu%,5))=2:
  192.  underline
  193. grey(
  194. submenuhandle(mainmenu%,5)+8,
  195.  n%=(FNsubmenuhandle(mainmenu%,5)+8)
  196.  !n%=!n% OR (1<<22):REM greyed out
  197. makemenu(text$,num%)
  198.  n%,m%,menu%,a%,b$,max%,ptr%,x%
  199.  menu% 28+num%*24
  200. text$,"|"):$menu%=
  201. text$,n%-1)
  202. menu%?12=7:menu%?13=2
  203. menu%?14=7:menu%?15=0
  204. menu%!20=44:menu%!24=0
  205. ptr%=menu%+4
  206.  x%=1 
  207.  num%
  208.    ptr%+=24:!ptr%=0:ptr%!4=-1
  209.   n%+=1
  210.   m%=
  211. text$,"|",n%)
  212.   b$=
  213. text$,n%,m%-n%)
  214.  (m%-n%)>max% 
  215.  max%=m%-n%
  216.  m%-n%>11 
  217.  a% (m%-n%)
  218.     $a%=b$
  219.     ptr%!8=&7000121
  220.     ptr%!12=a%
  221.     ptr%!16=0
  222.     ptr%!20=m%-n%
  223. #    
  224.  like indirected text icon
  225.     ptr%!8=&7000021
  226.     $(ptr%+12)=b$
  227.   n%=m%
  228. /!ptr%=1<<7:
  229.  this should point to last item
  230. menu%!16=(max%*16)+16
  231. =menu%
  232. submenuhandle(menu%,num%):
  233.  returns start of item in menu block
  234. =menu%+28+(num%-1)*24
  235. grey(ptr%,flag%)
  236.  flag% 
  237.  !ptr%=!ptr% 
  238.  (1<<22) 
  239.  !ptr%=!ptr% 
  240. (1<<22)
  241. "Wimp_PollIdle",&3CB0,block%,start 
  242.  reason%,block%
  243. reason(reason%)
  244. "OS_ReadMonotonicTime" 
  245.  (now-start)>0
  246. start=start+600
  247. reason(reason%)
  248.  reason% 
  249.  0 : 
  250.  beep% 
  251.  start=start+120:
  252. beep: 
  253. check_time(
  254.  1 : 
  255. redrawwindow
  256.  2 : 
  257. "Wimp_OpenWindow",,block%
  258.  3 : 
  259. closewindow(block%!0)
  260.  6 : 
  261. click(block%!12,block%!16,block%!8)
  262.  8 : 
  263. keypress(block%!24)
  264.  9 : 
  265. menuselect
  266.  17,18 : 
  267. message
  268. report(
  269. $+" at line "+
  270. ),1):
  271. windowtitle(alarms%))<>"*" 
  272. "SlidingHeap_VerifyHeap",slidingheapbase%
  273. "Font_LoseFont",fonthandle%
  274. "Wimp_CloseDown"
  275. centre(warning%)
  276. freepointer
  277.  ptr%,x%,y%
  278. screensize(x%,y%)
  279. ptr%=!temp%
  280. ptr%?0=1
  281. ptr%?1=0:ptr%?2=0
  282. ptr%?3=0:ptr%?4=0
  283. #ptr%?5=x% 
  284.  &FF:ptr%?6=x% 
  285. #ptr%?7=y% 
  286.  &FF:ptr%?8=y% 
  287. "OS_Word",21,ptr%
  288. dohelp
  289.  hlp$,keep%
  290. keep%=block%!8
  291.  block%!32 
  292.     2   
  293.  -2:hlp$="Click MENU to test menu help.|M"
  294.  main%,edit%,alarms%,repeat%,info%,alert%,warning%: hlp$=
  295. windowhelp(block%!32,block%!36)
  296.  hlp$=
  297. menuhelp
  298. block%!12=keep%
  299. block%!16=&503
  300. !block%=(25+
  301.  hlp$)
  302. $(block%+20)=hlp$+
  303.  hlp$<>"" 
  304.  "Wimp_SendMessage",17,block%
  305. menuhelp
  306.  a$,x$
  307. "Wimp_GetMenuState",0,block%
  308. submenuhandle(lib_lastopen%,1+block%!0)+8) 
  309.  (1<<22) 
  310.  x$="g" 
  311.  x$="m":
  312.  check for greyed-out flag
  313. #param1$=
  314. message_lookup("this")
  315.  lib_lastopen% 
  316.  mainmenu%:
  317.  block%!4>=0 
  318.  x$="rp":block%!0=block%!4:
  319.  submenu
  320. 6         a$=
  321. message_looksub("m"+x$+
  322. (1+block%!0))
  323.  alarmmenu%:
  324. 6         a$=
  325. message_looksub("a"+x$+
  326. (1+block%!0))
  327. =a$+"."
  328. windowhelp(window%,icon%)
  329.  a$,d$,f$
  330.  window% 
  331.  main%:param1$=p$:a$=
  332. message_looksub("main")
  333.  alarms%:a$=
  334. message_lookup("alrm")
  335.  info%:a$=
  336. message_lookup("info")
  337.  warning%:
  338.  icon%=0 
  339.  param1$=
  340. message_lookup("mm3"):a$=
  341. message_looksub("w0"):
  342. message_lookup("w"+
  343. (icon%))
  344.  edit%:a$=
  345. message_lookup("edit")
  346.     a$+=".|M"
  347.  icon% 
  348. +-      
  349. 0,1,14,13,26,27,-1:a$=
  350. (a$)-3)
  351. ,D      
  352. 5,2,3,4:f$=
  353. message_lookup("sa"):d$=
  354. message_lookup("dt")
  355. -@      
  356.  12:f$=
  357. message_lookup("sa"):d$=
  358. message_lookup("td")
  359. .H      
  360. 18,19,16,17:f$=
  361. message_lookup("as"):d$=
  362. message_lookup("td")
  363. /J      
  364. 6,7,8,9,10,11:f$=
  365. message_lookup("as"):d$=
  366. message_lookup("dt")
  367. 0-      
  368. :a$+=
  369. message_lookup("e"+
  370. (icon%))
  371. 1I    
  372.  d$<>"" 
  373.  param1$=d$:param2$=f$:a$=a$+
  374. message_looksub("when")
  375.  repeat%:a$=
  376. message_lookup("rept")
  377.  icon% 
  378. 45      
  379.  1,2,4,5:d$=
  380. message_lookup("as"):f$="int"
  381. 51      
  382.  3,6:d$=
  383. message_lookup("sa"):f$="int"
  384.       
  385.  7,0,16,-1:
  386.  labels
  387. 73      
  388. geticontext(repeat%,icon%):f$="day"
  389. 8^    
  390.  d$<>"" 
  391.  param1$=d$:param2$=
  392. message_lookup("this"):a$+=".|M"+
  393. message_looksub(f$)
  394. =a$+"."
  395. report(text$,flag%)
  396. name$=p$
  397.  flag% 
  398.  param1$=p$:name$=
  399. message_looksub("warn")
  400.  flag%>255 
  401.  name$=
  402. message_lookup("esc"):flag%=19
  403. !block%=255
  404. $(block%+4)=text$+
  405.  "Wimp_ReportError",block%,flag%,name$ 
  406.  ,errclick%
  407. click(win%,icon%,button%)
  408.  worky%,n%,m%,txt$
  409.  button%=2 
  410. menuclick(win%,block%!0,block%!4):
  411. worky%=block%!4
  412.  handles all non-MENU-clicks/drags
  413.  win% 
  414.  warning%:
  415. warningclick(icon%)
  416.  main%:
  417.  Double(*1)/click(*256)/drag(*16)
  418.  button% 
  419. P!    
  420.  Select-double-click
  421. Q]          
  422. geticontext(edit%,mth%)="Fish!" 
  423. settoday:
  424.  first time window opened today
  425.           
  426. clearalarm
  427. S           
  428. openwindow(edit%)
  429. T'    
  430.  16,64:!block%=win%:block%!4=1
  431. U9         
  432. "Wimp_DragBox",,block%:
  433.  drag whole window
  434. V3      
  435.  256:
  436.  SYS"Wimp_GetPointerInfo",,block%:
  437. W'               
  438. openwindow(alarms%)
  439. X0           
  440.  Adjust-click opens as permanent
  441. Y@    
  442.  1024:
  443. openwindow(main%):
  444.  Select-click brings to front
  445.  edit%:
  446.  icon% 
  447. ].      
  448.  rept%:n%=
  449. iconselected(win%,rept%)
  450. ^k                 
  451. openrepeatwindow 
  452. closewindow(repeat%):
  453.  open window next to edit% or close it
  454. _V      
  455.  reset%:
  456. clearalarm:
  457. settoday:
  458. "Wimp_SetCaretPosition",edit%,m1%,0,0,-1,-1
  459. `F      
  460.  cancel%:
  461. closewindow(edit%):
  462.  this will also close repeat%
  463. a6      
  464.  edit_ok%:
  465. newalarm 
  466. closewindow(edit%)
  467. bn      
  468.  hrup%,hrdown%,minup%,mindown%,dayup%,daydn%,mthup%,mthdn%,yrup%,yrdown%:
  469. changetime(icon%,button%)
  470. c        
  471.  repeat%:
  472. repeat_or_delay(win%,icon%,button%,rep_interval%,rep_type%)
  473.  alarms%:
  474.  count% 
  475. f@                block%!0=win%:
  476. "Wimp_GetWindowInfo",,block%
  477. g5                worky%=worky%+block%!24-block%!16
  478. i&                  n%=
  479. line(worky%)
  480. jU                  whichinmenu%=n%:
  481.  so we know which alarm to alter in FNnewalarm
  482. kA                  
  483. editalarm(n%):
  484.  only reports double-clicks
  485.                
  486.  alert%:
  487. freepointer:
  488. alarm_gone_off
  489. oA            
  490.  clicks should only be detected over the OK icon
  491. menuclick(window%,x%,y%)
  492.  handle%
  493.  window%=alert% 
  494.  window%=alarms% 
  495.  count% 
  496. putnameinmenu(block%!4):handle%=alarmmenu% 
  497.  handle%=mainmenu%
  498. "Wimp_CreateMenu",,handle%,x%-64,y%+20
  499. lib_lastopen%=handle%
  500. menuselect
  501.  d$,ptr%,n%
  502.  lib_lastopen% 
  503.  mainmenu%:
  504.  1+block%!0 
  505. savealarms
  506. openwindow(alarms%)
  507. click(main%,0,4):
  508.  fake double-click on main window (set new alarm)
  509. readlastalarm:
  510.  insert last alarm to go off back into list
  511.         
  512.  1+block%!4 
  513. &              
  514.  0,1:
  515. check_time(1)
  516. /              
  517. copy_alarm(
  518. top_alarm,
  519.          
  520.  alarmmenu%:
  521.  1+block%!0 
  522. editalarm(whichinmenu%)
  523. (    
  524. deletealarm(whichinmenu%,
  525. '    
  526. copy_alarm(whichinmenu%,
  527. +    
  528.  4:ptr%=
  529. doublepling(whichinmenu%)
  530. %           n%=
  531. decodedate(ptr%+4)
  532.              
  533.  m%=0 
  534.  &18 
  535. 3              !(!repeat_time%+(m%))=block%!(m%)
  536.             
  537. F           d$=
  538. nextrepeat(ptr%,
  539. message_lookup("format"),
  540. now(d$))
  541. E           
  542.  throw away result - FNnextrepeat alters actual alarm
  543. ,           
  544. sort:
  545. resizewindow(count%,
  546.            
  547.  update window
  548. "Wimp_GetPointerInfo",,block%
  549.  block%!8=1 
  550. "Wimp_CreateMenu",,lib_lastopen%
  551. warningclick(icon%)
  552. closewindow(warning%):
  553.  make sure we restore caret
  554. freepointer:
  555.  icon% 
  556. savealarms
  557. :         
  558.  shutdown% 
  559. "Wimp_ProcessKey",508 
  560.  restart shutdown if necessary
  561.  2:txt$=
  562. windowtitle(alarms%)
  563. $         txt$=
  564. txt$,1,
  565. (txt$)-2)
  566. '         
  567. changetitle(alarms%,txt$)
  568. :        
  569.  discard - pretend data not unsaved after all
  570. 9        
  571.  shutdown% 
  572. "Wimp_ProcessKey",508 
  573.          shutdown%=
  574.  -----------Comparison routine for OS_HeapSort----------------------
  575. assembler(length%)
  576.  pass%
  577.  ourcode% length%
  578. L%=ourcode%+length%
  579.  first pass - enable range check,
  580.  i.e. OPT 8
  581.  second pass - enable error report
  582.  and range check, i.e. OPT 10
  583.  pass%=8 
  584.  set P% to start of our code
  585.  on each pass
  586.  P% = ourcode%
  587.  now invoke the assembler
  588.  [OPT pass%
  589. & ; set value of OPT as appropriate
  590. D ; on entry R0 and R1 are pointers to words containing addresses
  591.  ; of start of strings
  592.   LDR R0, [R0]        ;R0=!R0
  593.   LDR R1, [R1]        ;R1=!R1
  594.  LDR R0, [R0]
  595. . LDR R1, [R1]        ; 'double-pling' them
  596. S R2, R0, R1     ;check if either R1 or R0 is zero
  597.  BEQ quickexit
  598.  ADD R0,R0,#4
  599. > ADD R1,R1,#4        ;move pointers to start of timestring
  600. J LDRB R2, [R0], #1   ;load R2 with contents of address contained in R0
  601. J LDRB R3, [R1], #1   ;load R3 with contents of address contained in R1
  602.  CMP R2, R3
  603. S LDREQB R2, [R0], #1 ;if they were the same, perform further check on next byte
  604.  LDREQB R3, [R1], #1
  605. E CMPEQ R2, R3        ;only compare if necessary (saves branching)
  606.  LDREQB R2, [R0], #1
  607.  LDREQB R3, [R1], #1
  608.  CMPEQ R2, R3
  609.  LDREQB R2, [R0], #1
  610.  LDREQB R3, [R1], #1
  611.  CMPEQ R2, R3
  612.  LDREQB R2, [R0], #1
  613.  LDREQB R3, [R1], #1
  614. J CMPEQ R2, R3        ;compare first five bytes (unroll loop for speed)
  615.  LDReqB R2, [R0,#-6]
  616.  LDReqB R3, [R1,#-6]
  617. D CMPeq R2, R3       ;finally check repeat byte if times are same
  618.  MOV R15, R14
  619.  .quickexit
  620. 2 CMP R0, R1          ;do comparison right away
  621. & MOV R15, R14        ;exit routine
  622.  we have now left the assembler
  623.  pass%
  624. loadwindow(name$)
  625.  n%,ptr%
  626. "Wimp_LoadTemplate",,!temp%,mainind%,timeblock%-36,-1,name$ 
  627.  ,,mainind%
  628.  timeblock% immediately follows mainind% and is 36 bytes long
  629. "Wimp_CreateWindow",,!temp% 
  630. changetitle(window%,name$)
  631.  n%,flag%
  632. windowinfo(window%)
  633. $(n%!76)=name$
  634. flag%=n%!32
  635.  (flag% 
  636.  1<<16)=0 
  637.  window is not open - don't redraw area
  638.  "Wimp_ForceRedraw",-1,n%!4,n%!16,n%!12,(n%!16)+40
  639. windowinfo(win%):
  640.  return info block
  641. n%=!temp%
  642. !n%=win%
  643. "Wimp_GetWindowInfo",,n%
  644.  no room for icons in block!
  645. seticontext(window%,icon%,text$)
  646. "!block%=window%:block%!4=icon%
  647. "Wimp_GetIconState",,block%
  648. $(block%!28)=text$
  649. block%!8=0:block%!12=0
  650. "Wimp_SetIconState",,block%
  651. geticontext(win%,icon%)
  652. !block%=win%:block%!4=icon%
  653. "Wimp_GetIconState",,block%
  654. =$(block%!28)
  655. message_lookup(token$)
  656.  text$,n%
  657. "XMessageTrans_Lookup",mdata%,token$,0 
  658.  ,,text$;n%
  659.  %1 text$=""
  660. =text$
  661. message_looksub(token$)
  662.  set global variables param1/2$ before calling
  663.  n%,text$
  664. "XMessageTrans_Lookup",mdata%,token$,!temp%,255,param1$,param2$,0,0 
  665.  ,,text$;n%
  666.  %1 text$=""
  667. =text$
  668. redrawwindow
  669.  n%,a$
  670.  "Wimp_RedrawWindow",,block% 
  671. block%!100=3
  672. "OS_Word",14,block%+100
  673. "Territory_ConvertTimeToOrdinals",-1,block%+100,block%+108
  674. block%!120=4
  675. !Bblock%!124=(block%!124)+1:
  676.  today includes tomorrow until 4 am
  677. ""a$=
  678. timestring(block%+108),4)
  679.  year month day & hour (red alarms are today)
  680. redraw(block%!0,block%!28,block%!32,block%!36,block%!40,a$)
  681.  "Wimp_GetRectangle",,block% 
  682. openwindow(whan%)
  683. block%!0=whan%
  684. "Wimp_GetWindowState",,block%
  685. block%!28=-1
  686. "Wimp_OpenWindow",,block%
  687.  whan%=edit% 
  688. "Wimp_SetCaretPosition",edit%,m1%,0,0,-1,-1
  689. openrepeatwindow
  690.  width%,height%,x%,y%
  691. block%!0=edit%
  692. "Wimp_GetWindowState",,block%
  693. x%=block%!12
  694. y%=block%!16
  695. block%!0=repeat%
  696. "Wimp_GetWindowState",,block%
  697. width%=block%!12-block%!4
  698. height%=block%!16-block%!8
  699. block%!4=x%
  700. block%!8=y%-height%
  701. block%!12=x%+width%
  702. block%!16=y%
  703. block%!28=-1
  704. "Wimp_OpenWindow",,block%
  705. seticontext(repeat%,rept_num%,
  706. (rep_interval%)):
  707. seticontext(repeat%,div%,
  708. message_lookup("i"+
  709. (rep_type%)))
  710. user_modechange:
  711.  redraw font icons
  712. "Font_LoseFont",fonthandle%
  713. "Font_FindFont",,"Homerton.Bold",12*16,12*16,0,0 
  714.  fonthandle%
  715. !block%=edit%
  716. block%!4=am%
  717. "Wimp_GetIconState",,block%
  718. M3block%!12=255<<24:
  719.  clear last eight bits of 32
  720. N9block%!8=fonthandle%<<24:
  721.  insert new fonthandle here
  722. "Wimp_SetIconState",,block%
  723. block%!4=pm%
  724. "Wimp_SetIconState",,block%
  725. check_time(
  726.  beep%):
  727.  don't ask me why... but otherwise it doesn't
  728.  beep if an alarm goes off outside the desktop 
  729.  icontext$)
  730.  h%,n%,m%,d$
  731. !block%=3
  732. "OS_Word",14,block%
  733. "Territory_ConvertTimeToOrdinals",1,block%,block%+8
  734.  This is supposed to make the program international, but I'm not convinced.
  735. block%!12=0
  736. ^0block%!8=0:
  737.  ignore seconds and centiseconds
  738. h%=block%!20
  739. `2n%=block%!16 
  740.  n% gives the 'fudge factor'
  741. m%=block%!16-n%
  742.  n%>2 
  743.  m%+=5:
  744.  round to nearest five minutes
  745.  m%>30 
  746. loopzero(h%+1,23):
  747.  round up to next hour
  748. d;d$=
  749. timestring(block%+8):
  750.  before block% gets corrupted
  751.  ((m% 
  752.  60)=0 
  753. message_lookup("o")
  754.  'AND h%' means AND h% > 0 - can't have 'midnight o'clock'!
  755. icontext$="It's "+
  756. message_lookup("a"+
  757. (n%))+
  758. message_lookup("m"+
  759. (m%))+
  760. message_lookup("hr"+
  761. (h%))+a$+".":
  762.  date in human format
  763. h"=d$:
  764.  date in text code format
  765. check_time(sound%):
  766.  should be called once every 6 seconds
  767.  h%,n%,m%,a$,d$
  768. now(a$)
  769. seticontext(main%,0,a$)
  770.  count%=0 
  771.  otherwise check if alarm is due
  772. top_alarm
  773. a$=$(
  774. doublepling(n%)+4)
  775.  d$>=a$ 
  776. set_off_alarm(n%,d$,sound%)
  777. timestring(ptr%)
  778.  We need to know minutes, hours, day, month and year
  779.  a$,n%
  780.  n%=8 
  781.  &14 
  782. yI  a$=
  783. (65+ptr%!n%)+a$:
  784.  encode it backwards so that string comparison
  785. z7                           
  786.  gives the right result
  787. (65+ptr%!&18-1990)+a$:
  788.  year byte cannot exceed 256
  789.  and they complain when people use TWO characters to represent the year?!!
  790.  Why use two when one will do?
  791. loadalarms
  792.  i%,n%,m%,ptr%,type%,dum%,a$,txt$
  793. saveerror
  794.  (Choicespath$+"Alarms")
  795. #i%,anchors% 
  796.  anchors%=0
  797. count%=anchors%
  798.  anchors%=0 
  799. resizewindow(anchors%,
  800. extend_named_sliding_block(anchor_block%,anchors%*4)
  801. 9ptr%=!anchor_block%:
  802.  point to start of sliding block
  803.  n%=0 
  804.  (anchors%-1)*4 
  805. C  ptr%!n%=
  806. create_anchor(
  807. (65+n%)):
  808.  give them one-letter names
  809. #i%,a$
  810. #i%,txt$
  811.   m%=
  812. (txt$)
  813.  notfont% 
  814. "Wimp_TextOp",1,
  815. striptabs(txt$,
  816.  m%:m%=m%/16
  817.  measure string in desktop font
  818.  we are assuming a standard width of 16 pixels per char elsewhere
  819.  m%>max% max%=m%
  820. create_named_sliding_block(ptr%!n%,4+
  821. (txt$)+5+2)
  822.  enough space for the 5-byte date string, the message and 2 linefeeds
  823.  and repeat block at beginning
  824.   m%=ptr%!n%
  825.    $(!m%+4)=a$:$(!m%+10)=txt$
  826. )  type%=
  827. #i%:?(!m%)=type%:
  828.  rep_type%
  829.  type% 
  830.  type%=
  831. #i%:?(!m%+1)=type%:type%=
  832. #i%:?(!m%+2)=type%:
  833.  dum%=
  834. #i%:dum%=
  835. +  dum%=
  836.  get (unused) rest of word
  837.  Sliding block where each element is the address of a word of memory
  838.  holding the address of the start of a string.   Confused?  I am!
  839.  shouldn't be necessary - unless Generator was used to create alarms
  840. resizewindow(anchors%,
  841. savealarms
  842.  i%,txt$,n%,m%,p%
  843. saveerror:
  844.  count%=0 
  845. "Remove "+Choicespath$+"Alarms"
  846.  *Remove doesn't give an error if file not found
  847.  "CDir "+
  848. Choicespath$) 
  849. "  i%=
  850.  (Choicespath$+"Alarms")
  851. #i%,count%
  852.   n%=
  853. top_alarm
  854.   p%=n%+count%
  855.  n%<p%
  856.     m%=
  857. doublepling(n%)
  858. #i%,$(m%+4)
  859. #i%,$(m%+10)
  860. #i%,?m%
  861. #i%,m%?1
  862. #i%,m%?2
  863. #i%,0:
  864.  fill in word
  865.     n%+=1
  866. txt$=
  867. windowtitle(alarms%)
  868. txt$)="*" 
  869.  txt$=
  870. txt$,1,
  871. (txt$)-2)
  872. changetitle(alarms%,txt$)
  873.  this involves a call to FNwindowinfo
  874. n%=!temp%+100
  875. *!n%=main%:
  876. "Wimp_GetWindowInfo",,n%
  877.  get position of main% into !temp%+100 after position of alarms% at !temp%
  878. "XOS_File",10,Choicespath$+"Position",&FFD,,!temp%,!temp%+128+28
  879. windowtitle(win%)
  880. windowinfo(win%)
  881. =$(n%!76)
  882. saveerror
  883. param1$=
  884. report(
  885. message_looksub("io"),16)
  886. close_named_channel(
  887. gstrans(Choicespath$+"Alarms")):
  888. gstrans(text$) :
  889.  corrupts block%
  890. "OS_GSTrans",text$,block%,255 
  891.  ,,num%
  892. !(block%+num%)=13
  893. =$block%
  894. close_named_channel(file$)
  895.  n%,f%,x%,V
  896.  n%=255 
  897.  &20009,254,n% 
  898.  (S% 
  899.  &800)=0 
  900. /    
  901.  &20009,7,n%,block%,,,255 
  902.  ,,,,,f%;V
  903.     block%?(255-f%)=13
  904. 1    
  905.  1)=0 
  906.  $block%=file$ 
  907.  x%=n%:n%=-1
  908. #x%:=
  909.  Find open channel and get handle
  910.  SYS &20009 = SYS"XOS_Args". Based on procedure by Dave Lawrence
  911. redraw(window%,minx%,miny%,maxx%,maxy%,time$)
  912.  worktop%,xedge%,top%,ptr%,line%,a$,om%,ox%
  913.  window% 
  914.  alarms%:
  915.     ptr%=!anchor_block%
  916. 5    xedge%=14+block%!4-block%!20:
  917.  left-hand edge
  918. $    worktop%=block%!16-block%!24
  919. Y    
  920.  maxy%>(worktop%-44) 
  921. setGCOL(0,68,153):
  922.  minx%,worktop%-44,maxx%-minx%,44
  923.  count% 
  924.       top%=worktop%-52-26
  925. 1      ox%=(top%-maxy%+17)
  926.  ox%<0 
  927.  ox%=0
  928.       line%=
  929. top_alarm
  930. .      om%=1+ox%+line%+(maxy%+17-miny%)
  931. 5      
  932.  om%>(line%+count%-1) 
  933.  om%=line%+count%-1
  934.       
  935.  (ox%+line%)<=om%
  936. J        
  937. printalarmline(ptr%!((line%+ox%)*4),xedge%,top%-ox%*44,time$)
  938.         ox%+=1
  939.       
  940.         
  941.  alert%:
  942.     line%=
  943. top_alarm
  944.      ptr%=
  945. doublepling(line%)
  946.     a$=$(ptr%+10)
  947.     top%=-1*((block%!16-block%!8)DIV2)-(45*(?ptr%=0))-26
  948. 7    top%=-1*((block%!16-block%!8)
  949. 2)-(45*(?ptr%=0))
  950.     line%=
  951. '    
  952. virtualicon(top%,
  953. a$,line%-1))
  954.     a$=
  955. a$,line%+1)
  956.     line%=
  957. *    
  958. virtualicon(top%-60,
  959. a$,line%-1))
  960.     a$=
  961. a$,line%+1)
  962. !    
  963. virtualicon(top%-120,a$)
  964. !block%=window%
  965. virtualicon(maxy%,text$)
  966.  ptr%
  967. ptr%=block%+152
  968. !ptr%=18
  969. ptr%!4=maxy%-60
  970. ptr%!8=694
  971. ptr%!12=maxy%
  972. ptr%!16=&7000119
  973. $block%=text$
  974. ptr%!20=block%
  975. $(block%+148)=""
  976. ptr%!24=block%+148
  977. ptr%!28=
  978. (text$)
  979. "Wimp_PlotIcon",,ptr%
  980. printalarmline(p%,x%,y%,time$)
  981.  n%,p2%,a$,red%
  982. a$=$(!p%+4)
  983. red%=(a$<time$)
  984.  red% 
  985. setGCOL(221,0,0) 
  986. setGCOL(0,0,0)
  987.  ?(!p%) 
  988.  4,x%-14,y%+2:
  989.  4,x%-14,y%+22:
  990.  85,x%-4,y%+12
  991.  first byte at !p% is the repeat byte - plot triangle to left of text
  992. decodedate(!p%+4)
  993. "Territory_ConvertDateAndTime",-1,p2%,block%+36,52,"%W3, %ZDY%ST %M3 %CE%YR %Z12:%MI %AM"+
  994.  ,n%:?n%=13
  995. !"a$=$(block%+36):n%=
  996. a$," ",18)
  997. desktext(
  998. a$,n%-1),x%,y%,red%)
  999. desktext(
  1000. a$,n%+1),x%+304,y%,red%)
  1001. desktext($(!p%+10),x%+456,y%,red%)
  1002. desktext(s$,x%,y%,red%)
  1003.  width%
  1004.  notfont% 
  1005.  x%,y%+26:
  1006.  red% 
  1007. "Wimp_TextOp",0,&0000F000,&F0F0F000 
  1008. "Wimp_TextOp",0,&00000000,&F0F0F000
  1009.   s$=
  1010. striptabs(s$,
  1011.  "Wimp_TextOp" takes tab char as string terminator - although PRINT renders it as a space, a fact formed part of the basic concept of the program :-( 
  1012. "Wimp_TextOp",2,s$,,,x%,y%
  1013.  x%,y%:
  1014. a$,n%-1):
  1015.  x%+304,y%:
  1016. a$,n%+1):
  1017.  x%+456,y%:
  1018.  $(!p%+10)
  1019. setGCOL(r%,g%,b%)
  1020. "ColourTrans_SetGCOL",(b%<<24)+(g%<<16)+(r%<<8),,,1<<8,0
  1021. top_alarm:
  1022.  Returns offset (in anchor_block%) of 1st alarm
  1023. doublepling(n%)=0
  1024.   n%+=1
  1025. nextup(offset%,ptr%):
  1026.  returns number of hrs/days etc we can increase by
  1027.  before triggering next day/month etc.
  1028.  offset% 
  1029.  8:n%=60-(ptr%!offset%)
  1030.  &C:n%=24-(ptr%!offset%)
  1031.  &10:n%=
  1032. maxdays(ptr%!&14,ptr%!&18)-ptr%!offset%
  1033.  ignore weeks - treat as 7 day repeat
  1034.  &14:n%=12-(ptr%!offset%)
  1035.  &18:n%=ptr%!offset%:
  1036.  have as many years as you like
  1037. H:=n%+1:
  1038.  we want to go one over limit to trigger change
  1039. line(worky%):
  1040.  which alarm line was clicked on?
  1041. L+n%=(-worky%-52)
  1042.  worky% is negative
  1043.  n%>=count% 
  1044.  n%=count%-1
  1045.  we can't close the window small enough when there is only one alarm
  1046.  n%=-1 
  1047.  n%=0
  1048. top_alarm
  1049. maxdays(m%,y%):
  1050.  number of days in a month
  1051.  n%=0 
  1052.  &10 
  1053.   block%!n%=1
  1054.  blank block
  1055. block%!&14=m%
  1056. Y)block%!&18=y%:
  1057.  in case of leap years
  1058. "Territory_ConvertOrdinalsToTime",-1,block%+60,block%
  1059. "Territory_ReadCalendarInformation",-1,block%+60,block%
  1060. =block%!12
  1061. doublepling(alarm%):
  1062.  returns address of text of alarm alarm%
  1063.  ptr%
  1064. a#ptr%=!(!anchor_block%+alarm%*4)
  1065. =!ptr%
  1066. looped(NUM%,LIMIT%)  :
  1067.  transforms NUM to a no. between 1 and LIMIT
  1068. e =(LIMIT%+NUM%-1) 
  1069.  LIMIT% +1
  1070. loopzero(num%,limit%):
  1071.  does same for 0 to limit%
  1072.  limit%+=1
  1073. h%=(limit%+(num% 
  1074.  limit%))
  1075.  limit%
  1076. settoday
  1077. !block%=3
  1078. "OS_Word",14,block%
  1079. puttime(block%)
  1080. puttime(UTC%)
  1081.  h%,n%,m%,a$,d$
  1082. "Territory_ConvertDateAndTime",-1,UTC%,block%+24,30,"%W3%ZDY%ST
  1083. %CE%YR" 
  1084. ?n%=13
  1085. sJd$=$(block%+24):
  1086.  Preserve date (since we are about to corrupt block%)
  1087. "Territory_ConvertTimeToOrdinals",1,UTC%,timeblock%
  1088.  We want dates as strings, but time as numbers
  1089.  This is supposed to make the program international, but I'm not convinced.
  1090. w1n%=!minute% 
  1091.  n% gives the 'fudge factor'
  1092. !minute%=!minute%-n%
  1093.  n%>2 
  1094.  !minute%+=5:
  1095.  round to nearest five minutes
  1096. m%=!minute%:h%=!hour%
  1097.  h%>11 
  1098. icongreyed(edit%,am%,1):
  1099. icongreyed(edit%,pm%,0):
  1100. icongreyed(edit%,pm%,1):
  1101. icongreyed(edit%,am%,0)
  1102.  m%>30 
  1103. loopzero(!hour%+1,23):
  1104.  round up to next hour
  1105.  ((m% 
  1106.  60)=0 
  1107. message_lookup("o")
  1108.  'AND h%' means AND h% > 0 - can't have 'midnight o'clock'!
  1109. seticontext(edit%,time%,
  1110. message_lookup("m"+
  1111. (m%))+
  1112. message_lookup("hr"+
  1113. (h%))+a$)
  1114.  Now do date
  1115. seticontext(edit%,day%,
  1116. d$,3))
  1117. seticontext(edit%,date%,
  1118. d$,4,n%-4))
  1119.     n%+=1
  1120. ",n%)
  1121. seticontext(edit%,mth%,
  1122. d$,n%,m%-n%))
  1123. seticontext(edit%,year%,
  1124. d$,m%+1))
  1125. icongreyed(window%,icon%,n%)
  1126. putbit(window%,icon%,22,n%)
  1127. iconselect(window%,icon%,n%)
  1128. putbit(window%,icon%,21,n%)
  1129. clearalarm
  1130. iconselect(edit%,rept%,0):
  1131.  clear repeat icon
  1132. Crep_interval%=default_rep_interval%:rep_type%=default_rep_type%
  1133. write_weekdays(0)
  1134.  reset repeat window
  1135. closewindow(repeat%)
  1136.  n%=0 
  1137. seticontext(edit%,
  1138. ("m"+
  1139. (n%+1)+"%"),"")
  1140. closewindow(window%)
  1141. block%!0=window%
  1142. "Wimp_CloseWindow",,block%
  1143.  window% 
  1144.  edit%:
  1145. closewindow(repeat%):a$=
  1146. message_lookup("ws"):
  1147. changetitle(edit%,a$)
  1148.  warning%,alert%:
  1149. "XWimp_SetCaretPosition",block%!200,block%!204,block%!208,block%!212,block%!216,block%!220
  1150.  put caret back in window from which we stole it (if possible)
  1151.        beep%=
  1152.  main%:
  1153. iconselected(win%,icon%)
  1154. block%!0=win%
  1155. block%!4=icon%
  1156. "Wimp_GetIconState",,block%
  1157. =(block%!24>>21) 
  1158. fonticon(text$,handle%)
  1159.  n%,ptr%
  1160.  n% 6
  1161. $n%=text$
  1162. $(n%+3)="F17"
  1163. block%!0=edit%
  1164. ptr%=block%+4
  1165. ptr%!0=648
  1166. ptr%!8=704
  1167.  text$ 
  1168.  "AM":ptr%!4=-112:ptr%!12=-68
  1169. "PM":ptr%!4=-156:ptr%!12=-112
  1170. :ptr%!16=&400159 
  1171.  handle%<<24:
  1172.  insert fonthandle here
  1173. ptr%!20=n%
  1174. ptr%!24=n%+3
  1175. ptr%!28=3
  1176. "Wimp_CreateIcon",edit%,block% 
  1177. keypress(key%)
  1178.  block%!0 
  1179.  edit%:
  1180.  key% 
  1181. ]    
  1182.  &12:
  1183. putbit(edit%,rept%,21,
  1184. iconselected(edit%,rept%)-1):
  1185. click(edit%,rept%,4):n%=1
  1186. <    
  1187.  CTRL-R: toggle state of repeat icon and fake click
  1188. @    
  1189.  &1B:
  1190. closewindow(edit%):
  1191.  this will also close repeat%
  1192. newalarm 
  1193. .             
  1194. iconselect(edit%,edit_ok%,1)
  1195. )             
  1196. closewindow(edit%):n%=1
  1197. .             
  1198. iconselect(edit%,edit_ok%,0)
  1199.             
  1200.         
  1201.  alert%,warning%:
  1202.  key%=13 
  1203. click(block%!0,0,4):n%=1:
  1204.  fake default click if 'hot-key press' detected
  1205. j                       
  1206.  key%=27 
  1207.  block%!0=warning% 
  1208. click(warning%,1,4):n%=1:
  1209.  fake 'Cancel' click
  1210.  n%=0 
  1211. "Wimp_ProcessKey",key%
  1212. newalarm
  1213.  i%,n%,ptr%,txt$,m%,a$
  1214. timestring(timeblock%)
  1215.  hope that timeblock% is correctly set up by PROCchangetime/PROCputtime
  1216. !block%=3
  1217. "OS_Word",14,block%
  1218. "Territory_ConvertTimeToOrdinals",1,block%,block%+8
  1219. timestring(block%+8)>a$ 
  1220. report(
  1221. message_lookup("early"),0):=
  1222.  count% 
  1223. top_alarm 
  1224.  i%=anchors%:
  1225.  avoid address exceptions
  1226. windowtitle(edit%)=
  1227. message_lookup("we")
  1228.  i%=whichinmenu%+1:count%-=1
  1229.  when editing we don't actually want to increase the number of alarms
  1230. Ztxt$=
  1231. geticontext(edit%,m1%)+
  1232. geticontext(edit%,m2%)+
  1233. geticontext(edit%,m3%)
  1234. (txt$)
  1235.  notfont% 
  1236. "Wimp_TextOp",1,
  1237. striptabs(txt$,
  1238.  m%:m%=m%/16
  1239.  m%>max% max%=m%:
  1240.  for resizing window
  1241. allocate_alarm_block(i%,txt$)
  1242. iconselected(edit%,rept%) 
  1243.  ?m%=rep_type%:m%?1=rep_interval%:m%?2=
  1244. read_weekdays 
  1245.  !m%=0
  1246. $(m%+4)=a$:$(m%+10)=txt$
  1247. resizewindow(count%,
  1248. allocate_alarm_block(top%,txt$):
  1249.  must know txt$ so block is right size
  1250.  m%,n%,ptr%
  1251.  top% 
  1252. J  n%=(top%-1)*4:
  1253.  top% is the top *alarm* - we want the preceding slot
  1254. D  count%+=1:
  1255.  no. of alarms is changing - but not no. of anchors
  1256.   ptr%=!anchor_block%
  1257. extend_named_sliding_block(ptr%!n%,4+
  1258. (txt$)+5+2)
  1259.   m%=
  1260. doublepling(top%-1)
  1261.  no empty slots
  1262. P  n%=anchors%*4:
  1263.  will be anchors%-1 when we increment anchors% in next line
  1264. !  anchors%+=1:count%=anchors%
  1265. extend_named_sliding_block(anchor_block%,anchors%*4)
  1266. H  ptr%=!anchor_block%:
  1267.  it may well have moved after resizing block!
  1268. &  ptr%!n%=
  1269. create_anchor(
  1270. (65+n%))
  1271. create_named_sliding_block(ptr%!n%,4+
  1272. (txt$)+5+2)
  1273. !  m%=
  1274. doublepling(anchors%-1)
  1275. alarmtowindow(num%)
  1276.  alarm%,ptr%,n%,a$
  1277. alarm%=
  1278. doublepling(num%)
  1279. n%=?alarm%
  1280. )  rep_type%=n%:rep_interval%=alarm%?1
  1281. iconselect(edit%,rept%,1)
  1282. seticontext(repeat%,rept_num%,
  1283. (rep_interval%))
  1284. seticontext(repeat%,div%,
  1285. message_lookup("i"+
  1286. (rep_type%)))
  1287. write_weekdays(alarm%?2)
  1288. click(edit%,rept%,4)
  1289.  simulate click on 'repeat' icon in order to open window
  1290.  next to where edit window will be
  1291. iconselect(edit%,rept%,0)
  1292. closewindow(repeat%)
  1293.  close repeat window if already open, and not wanted
  1294. 2ptr%=
  1295. decodedate(alarm%+4):
  1296.  Returns UTC block
  1297. puttime(ptr%)
  1298. a$=$(alarm%+10)
  1299. seticontext(edit%,m1%,
  1300. a$,n%-1))
  1301. a$,n%+1)
  1302. seticontext(edit%,m2%,
  1303. a$,n%-1))
  1304. a$,n%+1)
  1305. seticontext(edit%,m3%,a$)
  1306. deletealarm(num%,close%)
  1307.  ptr%
  1308.  close% 
  1309. closewindow(edit%):
  1310.  just in case
  1311.  but don't close if we are faking edit of last alarm to go off
  1312. ptr%=!anchor_block%
  1313. scrap_sliding_block(ptr%!(num%*4))
  1314. count%-=1
  1315. resizewindow(count%,
  1316.  block should already have been filled by PROCresizewindow
  1317.  (block%!32 
  1318.  1<<16) 
  1319. "Wimp_OpenWindow",,block%
  1320.  redraws window with bottom line missing if it is actually open
  1321.  (if not, it doesn't need redrawing & we certainly don't want it to pop up!)
  1322. changetime(icon%,button%)
  1323.  n%,h%,m%,y%,a$,d$
  1324.  icon% 
  1325.  hrup%,hrdown%:
  1326. ;E    !hour%+=(icon%=hrdown% 
  1327.  button%=1)-(icon%=hrup% 
  1328.  button%=1)
  1329. <3    
  1330.  Using ADJUST reverses direction of arrows
  1331.  minup%,mindown%:
  1332. >M    !minute%+=5*(icon%=mindown% 
  1333.  button%=1)-5*(icon%=minup% 
  1334.  button%=1)
  1335. ?0    
  1336.  increment/decrement hour appropriately
  1337.  dayup%,daydn%:
  1338. AF    !dayno%+=(icon%=daydn% 
  1339.  button%=1)-(icon%=dayup% 
  1340.  button%=1)
  1341.  mthup%,mthdn%:
  1342. CF    !month%+=(icon%=mthdn% 
  1343.  button%=1)-(icon%=mthup% 
  1344.  button%=1)
  1345.  yrup%,yrdown%:
  1346. EC    !yr%+=(icon%=yrdown% 
  1347.  button%=1)-(icon%=yrup% 
  1348.  button%=1)
  1349. adjusttime(timeblock%,icon%)
  1350. h%=!hour%
  1351. putbit(edit%,am%,22,(h%>11)*-1):
  1352. putbit(edit%,pm%,22,(h%<12)*-1):
  1353.  set am% and pm% according to whether h% is at least 12 or not
  1354. m%=!minute%
  1355.  m%>30 
  1356. loopzero(h%+1,23):
  1357.  round to next hour
  1358.  (m% 
  1359.  60=0 
  1360. message_lookup("o")
  1361.  'AND h%' - i.e. AND h% > 0 - can't have 'midnight o'clock'!
  1362. seticontext(edit%,time%,
  1363. message_lookup("m"+
  1364. (m%))+
  1365. message_lookup("hr"+
  1366. (h%))+a$)
  1367.  Now do date
  1368. "Territory_ConvertOrdinalsToTime",-1,block%,timeblock%
  1369. "Territory_ConvertDateAndTime",-1,block%,block%+24,30,"%W3%ZDY%ST
  1370. %CE%YR" 
  1371.  Let RISC-OS do the difficult bit this time!
  1372. ?n%=13
  1373. d$=$(block%+24)
  1374. seticontext(edit%,day%,
  1375. d$,3))
  1376. seticontext(edit%,date%,
  1377. d$,4,n%-4))
  1378. Y    n%+=1
  1379. ",n%)
  1380. seticontext(edit%,mth%,
  1381. d$,n%,m%-n%))
  1382. seticontext(edit%,year%,
  1383. d$,m%+1))
  1384. repeat_or_delay(window%,icon%,button%,
  1385.  interval%,
  1386.  type%)
  1387.  the delay window has same icons as repeat - so use same procedure for both!
  1388.  type%=1 
  1389.  m%=5 
  1390.  m%=1
  1391.             
  1392.  icon% 
  1393. d"              
  1394.  numup%,numdn%:
  1395. e\                  interval%+=m%*(icon%=numdn% 
  1396.  button%=1)-m%*(icon%=numup% 
  1397.  button%=1)
  1398. f6                  interval%=
  1399. looped(interval%,255)
  1400. g"              
  1401.  divup%,divdn%:
  1402. hR                  type%+=(icon%=divdn% 
  1403.  button%=1)-(icon%=divup% 
  1404.  button%=1)
  1405. i,                  type%=
  1406. looped(type%,6)
  1407. jS             
  1408.  type%=1 
  1409.  interval%-=interval% 
  1410.  interval%=0 
  1411.  interval%=5
  1412. kv             
  1413. seticontext(window%,rept_num%,
  1414. (interval%)):
  1415. seticontext(window%,div%,
  1416. message_lookup("i"+
  1417. (type%)))
  1418. read_weekdays
  1419.  o%,n%
  1420.  n%=9
  1421. q+  o%+=
  1422. iconselected(repeat%,n%)<<(n%-9)
  1423. write_weekdays(byte%)
  1424.  n%=9 
  1425. iconselect(repeat%,n%,1 
  1426.  (byte%>>(n%-9)))
  1427.  Note that the icons appear 'ticked' when NOT selected!
  1428. nottoday(byte%,now$)
  1429.  m%,ptr%,day%
  1430.  now$=
  1431. (254) 
  1432.  in case we press escape while calculating repeats
  1433. $block%=now$
  1434. ptr%=
  1435. decodedate(block%)
  1436. "Territory_ConvertDateAndTime",-1,ptr%,block%,10,"%wn"
  1437. day%=?block%-48
  1438. loopzero(day%-2,6)
  1439. (byte% 
  1440.  (1<<m%)) 
  1441. adjusttime(ptr%,icon%):
  1442.  calculate side-effects of change
  1443.  ptr% points to block of ordinals
  1444. #ptr%!&c+=(ptr%!8<0)-(ptr%!8>59)
  1445. &ptr%!&10+=(ptr%!&c<0)-(ptr%!&c>23)
  1446.  ptr%!&10>
  1447. maxdays(ptr%!&14,ptr%!&18) 
  1448.                
  1449.  icon% 
  1450. V                
  1451.  mthup%,mthdn%,yrup%,yrdown%:ptr%!&10=
  1452. maxdays(ptr%!&14,ptr%!&18)
  1453. ,                
  1454. :ptr%!&10=1:ptr%!&14+=1
  1455.                
  1456.  ptr%!&10=0 
  1457.  ptr%!&14-=1:ptr%!&10=
  1458. maxdays(ptr%!&14,ptr%!&18)
  1459. (ptr%!&18+=(ptr%!&14<1)-(ptr%!&14>12)
  1460. ptr%!8=
  1461. loopzero(ptr%!8,59)
  1462. !ptr%!&c=
  1463. loopzero(ptr%!&c,23)
  1464. !ptr%!&14=
  1465. looped(ptr%!&14,12)
  1466.  NewAlarm file format
  1467.  It seems reasonable to have alarms as a single data file inside application.
  1468.  i.e. no file type used
  1469.  First byte/no. - number of alarms in file
  1470.  Better check for absence of file, indicating 0 alarms also!
  1471.  If 0 alarms, don't claim memory
  1472.  For each alarm:  5-byte time string
  1473.                   text (* for task alarm?)
  1474.  Each alarm needs to have its own sliding block in case it gets edited
  1475.  and changes length - also so that we can sort them into date order
  1476.  Overheads will be enormous! :-(
  1477.  So we need to create a block to hold the anchors
  1478.  repeats follow after end of text string
  1479.  repeats: one byte for rep_type%
  1480.           if rep_type% > 0:
  1481.           one byte for number of intervals
  1482.           ?2? bytes containing days applicable
  1483.  Note that IN MEMORY the repeat block comes FIRST, followed by time string
  1484.  and then the text string.
  1485. putbit(whan%,icon%,bit%,state%)
  1486.  state% 
  1487.  state%=1
  1488. !block%=whan%
  1489. block%!4=icon%
  1490. block%!8=state%<<bit%
  1491. block%!12=1<<bit%
  1492. "Wimp_SetIconState",,block%
  1493. putnameinmenu(screeny%)
  1494.  worky%,a$,ptr%,n%,m%
  1495. !block%=alarms%
  1496. "Wimp_GetWindowInfo",,block%
  1497. )worky%=screeny%-(block%!16-block%!24)
  1498.  visible area - scroll offset;  top of work area in screen co-ordinates
  1499. Nwhichinmenu%=
  1500. line(worky%):
  1501.  global variable for use in PROCmenu_selection
  1502. #ptr%=
  1503. doublepling(whichinmenu%)
  1504. 'm%=?ptr%:
  1505.  is it a repeating alarm?
  1506. a$=$(ptr%+10):n%=
  1507.  n%>13 
  1508.  n%=13:
  1509. a$,12,1)=" "
  1510.  n%=12
  1511.  Abbreviate to 12 chars or to nearest word
  1512.  we assume not more than one space between words for simplicity's sake!
  1513. a$,n%-1)
  1514. param1$=a$
  1515. %ptr%=
  1516. submenuhandle(alarmmenu%,1)
  1517. &$(ptr%!12)=
  1518. message_looksub("del")
  1519. ptr%+=24
  1520. &$(ptr%!12)=
  1521. message_looksub("chn")
  1522. ptr%+=24
  1523. &$(ptr%!12)=
  1524. message_looksub("cpy")
  1525. ptr%+=24
  1526. grey(ptr%+8,(m%=0)):
  1527.  grey out 'defer' line if not repeating alarm
  1528. &$(ptr%!12)=
  1529. message_looksub("def")
  1530. resizewindow(lines%,change%):
  1531.  resize and redraw window (and asterisk)
  1532.  n%,a$
  1533. $n%=max%*16+480:
  1534.  n%<880 
  1535.  n%=880
  1536.  resize window appropriately
  1537. resize(alarms%,n%,(lines%+1)*44)
  1538.  make room for lines% lines plus a header line
  1539. !block%=alarms%
  1540. "Wimp_GetWindowInfo",,block%:
  1541.  get (new) visible area
  1542. n%=block%!32
  1543.  change% 
  1544.   a$=$(block%!76)
  1545. a$)<>"*" 
  1546.  a$+=" *":$(block%!76)=a$:
  1547.  mark window as changed
  1548.  (n% 
  1549.  1<<16)=0 
  1550.  window is not open - don't redraw area
  1551. "Wimp_ForceRedraw",-1,block%!4,block%!8,block%!12,block%!16+44
  1552.  update screen given absolute co-ordinates
  1553.  SOUND 1,-2,134,8
  1554. extend_named_sliding_block(workblock%,anchors%*4)
  1555. "OS_HeapSort",anchors%,(!workblock%)+(1<<30),ourcode%,,!anchor_block%,4
  1556.  "SlidingHeap_VerifyHeap",slidingheapbase%
  1557. resize(window%,width%,height%)
  1558.  LOCAL flags%,op%
  1559. ;!block%=0:block%!4=-height%:block%!8=width%:block%!12=0
  1560. "Wimp_SetExtent",window%,block%
  1561. !block%=window%
  1562. "Wimp_GetWindowState",,block%
  1563. block%!8=block%!16-height%
  1564. block%!12=block%!4+width%
  1565. block%!20=0:block%!24=0
  1566. flags%=block%!32
  1567. op%=(flags%>>16) 
  1568.  op%=0 block%!28=-3
  1569. "Wimp_OpenWindow",,block%
  1570. decodedate(ptr%)
  1571.  year,month,day,hour,minute
  1572.  n%,now$
  1573. now$=$(ptr%)
  1574. 4block%!0=0:block%!4=0:
  1575.  seconds and centiseconds
  1576.  n%=1 
  1577. +  block%!(&18-(n%-1)*4)=
  1578. now$,n%))-65
  1579. block%!&18+=1990
  1580.  block%!&18>2100 
  1581.  255," Too far in the future"
  1582. "Territory_ConvertOrdinalsToTime",-1,block%+100,block%
  1583. =block%+100
  1584. set_off_alarm(num%,now$,sound%)
  1585.  a$,ptr%,n%,m%
  1586. closewindow(edit%):
  1587.  just in case we happen to be editing...
  1588. doublepling(num%)
  1589. a$=$(n%+10)
  1590. extend_named_sliding_block(last%,10+
  1591. (a$)+1)
  1592. doublepling(num%):
  1593.  in case block slides
  1594. $(!last%+10)=a$
  1595. a$=$(n%+4):$(!last%+4)=a$
  1596.  take a copy of alarm data (but not repeats)
  1597. grey(
  1598. submenuhandle(mainmenu%,5)+8,
  1599.  ungrey menu entry - we now have a 'most recent alarm'
  1600. message_lookup("format")
  1601. +ptr%=
  1602. decodedate(n%+4):
  1603.  UTC time block
  1604.  m%=0 
  1605.  &18 
  1606. '  !(!repeat_time%+(m%))=block%!(m%)
  1607. "Territory_ConvertDateAndTime",-1,ptr%,block%,255,a$ 
  1608. ,ptr%
  1609. ?ptr%=13
  1610. seticontext(alert%,1,$block%)
  1611.  ?n%=0 
  1612. $     m%=1
  1613. &     m%=0
  1614. nextrepeat(n%,a$,now$)
  1615.  a$=CHR$(254) if we aborted repeat calculations
  1616.  a$<>
  1617. (254) 
  1618. seticontext(alert%,3,a$)
  1619. (254) 
  1620.  ?n%=0:
  1621. alarm_gone_off:
  1622.  if we aborted a repeating alarm, pretend that:
  1623.  a) it was not a repeating alarm and
  1624.  b) it has already gone off
  1625.  (?n%)>0 
  1626. nottoday(n%?2,now$) 
  1627. alarm_gone_off:
  1628.  check days byte
  1629.  n%?10=
  1630. ("*") 
  1631.  a$=$(n%+10):
  1632. "Wimp_StartTask",
  1633. striptabs(a$,
  1634. alarm_gone_off:
  1635.  Task alarms don't open the alert window (note DON'T substitute spaces here)
  1636.  note m% must be *0* to display icon (i.e. 'deleted' flag OFF)
  1637. putbit(alert%,2,23,m%):
  1638.  mark icon as deleted
  1639. putbit(alert%,3,23,m%):
  1640.  (unless there really is a repeat)
  1641. 6 beep%=sound%:
  1642. centre(alert%)
  1643. reason(0)
  1644.  beep%=
  1645.  Note that if beep%=1 then window opens but PROCbeep is silent
  1646. striptabs(text$,sub%)
  1647. text$,
  1648. D@   
  1649.  sub% 
  1650. text$,n%)=" " 
  1651.  text$=
  1652. text$,n%-1)+
  1653. text$,n%+1)
  1654. =text$
  1655. alarm_gone_off
  1656.  Called when alert window closed or after silent (not today) alarm calculated
  1657.  if there is a repeat, date will already have been altered
  1658. top_alarm
  1659. doublepling(n%))=0 
  1660. deletealarm(n%,
  1661.  PROCdeletealarm includes a sort
  1662. closewindow(alert%)
  1663. resizewindow(count%,
  1664.  add asterisk as alarm has been changed
  1665.  autosave% 
  1666. savealarms
  1667. check_time(
  1668.  check if another alarm is due
  1669. readlastalarm
  1670.  i%,m%,ptr%
  1671.  count% 
  1672. top_alarm 
  1673.  i%=anchors%:
  1674.  avoid address exceptions
  1675. ptr%=!last%
  1676. [+m%=
  1677. allocate_alarm_block(i%,$(ptr%+10))
  1678. \:ptr%=!last%:
  1679.  if blocks were shifted it may have moved
  1680. ])$(m%+4)=$(ptr%+4):$(m%+10)=$(ptr%+10)
  1681. ^$!m%=0:
  1682.  forget about any repeats
  1683. nextrepeat(ptr%,format$,now$)
  1684.  returns next repeat date as string
  1685.  also updates existing alarm with new date
  1686.  y%,boundary%,m%,store%,num%
  1687. num%=ptr%?1
  1688.  ?ptr% 
  1689.  1:y%=8
  1690.  2:y%=&C
  1691. 3:y%=&10
  1692. 4:num%=num%*7:y%=&10:
  1693.  treat weeks as seven days
  1694.  5:y%=&14
  1695. 6:y%=&18
  1696. oLstore%=num%:
  1697.  so we can add same again if repeat still earlier than now$
  1698. pKm%=!repeat_time%:
  1699.  saves recalculating this every time we call FNnextup
  1700. "Hourglass_On":
  1701.  in case of multiple repeats - 1/3 second delay so will
  1702.  not appear under normal circumstances
  1703.   num%=store%
  1704. v     boundary%=
  1705. nextup(y%,m%)
  1706. wy    
  1707.  boundary%<num% 
  1708.  m%!y%+=boundary% 
  1709.  m%!y%+=num%:
  1710.  increase time just enough to change next size of time unit up
  1711. adjusttime(m%,0)
  1712.     num%-=boundary%
  1713.  num%<1
  1714. timestring(m%)
  1715. (-113) 
  1716. escape(a$)
  1717.  continue until we have added entire specified amount
  1718.  a$>now$ 
  1719. nottoday(ptr%?2,a$)=
  1720. "Hourglass_Off"
  1721. (254) 
  1722.  =a$:
  1723.  i.e. we aborted in PROCescape
  1724. "Territory_ConvertOrdinalsToTime",-1,block%+100,!repeat_time%
  1725. "Territory_ConvertDateAndTime",-1,block%+100,block%,100,format$+
  1726. ?m%=13
  1727. K$(ptr%+4)=
  1728. timestring(!repeat_time%):
  1729.  substitute new time code for old
  1730. =$block%
  1731. escape(
  1732.  x%,b$,m%,ptr%
  1733. ptr%=!temp%
  1734. m%=!repeat_time%
  1735.  x%=8 
  1736.  &18 
  1737.   ptr%!x%=m%!x%
  1738.  OS calls seem to corrupt ordinals
  1739. "Territory_ConvertOrdinalsToTime",-1,block%+100,!repeat_time%
  1740. "Territory_ConvertDateAndTime",-1,block%+100,block%,100,format$+
  1741. ?m%=13
  1742. b$=$block%
  1743.  x%=8 
  1744.  &18 
  1745.   m%!x%=ptr%!x%
  1746.  restore ordinals
  1747. Uparam1$=b$:param2$=
  1748. message_lookup("this"):
  1749. report(
  1750. message_looksub("reach"),256)
  1751.  errclick%=1 
  1752. (254)
  1753.  The point of this is that CHR$(254) will *always* be greater than now$
  1754. "Hourglass_On"
  1755.  SYS"Wimp_Poll",0,block%
  1756.  to remove the error box and restore hourglass
  1757. editalarm(num%)
  1758. alarmtowindow(num%)
  1759. changetitle(edit%,
  1760. message_lookup("we"))
  1761.  will be restored to "Set" on window close
  1762. openwindow(edit%)
  1763. copy_alarm(num%,delete_old%)
  1764.  put alarm data into edit window
  1765.  ptr%,d$
  1766. ptr%=
  1767. doublepling(num%)
  1768.  delete_old% 
  1769.  $(ptr%+4)=
  1770. now(d$):
  1771.  d$ is dummy value
  1772. alarmtowindow(num%)
  1773. openwindow(edit%)
  1774.  delete_old% 
  1775. deletealarm(num%,
  1776. centre(win%)
  1777.  x%,y%,width%,height%,ptr%
  1778.  SYS"OS_ReadModeVariable",-1,11TO,,x%:SYS"OS_ReadModeVariable",-1,12TO,,y%:SYS"OS_ReadModeVariable",-1,4TO,,xe%:SYS"OS_ReadModeVariable",-1,5TO,,ye%
  1779.  x%=x%<<xe%:y%=y%<<ye%:
  1780. screensize(x%,y%)
  1781. x%=x%/2:y%=y%/2
  1782. !block%=win%
  1783. "Wimp_GetWindowState",,block%
  1784. width%=block%!12-block%!4
  1785. height%=block%!16-block%!8
  1786. block%!4=x%-width%/2
  1787. block%!12=x%+width%/2
  1788. block%!8=y%-height%/2
  1789. block%!16=y%+height%/2
  1790. ptr%=!temp%
  1791. ?ptr%=1
  1792. /ptr%?1=(block%!4)
  1793. 256:ptr%?2=(block%!4)
  1794. /ptr%?3=(block%!8)
  1795. 256:ptr%?4=(block%!8)
  1796. 1ptr%?5=(block%!12)
  1797. 256:ptr%?6=(block%!12)
  1798. 1ptr%?7=(block%!16)
  1799. 256:ptr%?8=(block%!16)
  1800. "OS_Word",21,ptr%
  1801. block%!28=-1
  1802. "Wimp_OpenWindow",,block%
  1803. "Wimp_GetCaretPosition",,block%+200:
  1804.  preserve old caret position
  1805. "Wimp_SetCaretPosition",win%,-1,0,0,-1,-1:
  1806.  for 'hot-keys'
  1807. screensize(
  1808.  xe%,ye%
  1809. "OS_ReadModeVariable",-1,11
  1810. "OS_ReadModeVariable",-1,12
  1811. "OS_ReadModeVariable",-1,4
  1812. ,,xe%
  1813. "OS_ReadModeVariable",-1,5
  1814. ,,ye%
  1815. x%=x%<<xe%:y%=y%<<ye%
  1816. message
  1817.  ptr%,n%,txt$
  1818.  block%!16 
  1819.  0      : 
  1820.  8      : 
  1821. windowtitle(alarms%))="*" 
  1822. =                 
  1823.  !block%<20 
  1824.  block%!20=0 
  1825.  shutdown%=
  1826. '                 block%!12=block%!8
  1827. <                 
  1828. "Wimp_SendMessage",19,block%,block%!4
  1829.  Acknowledge Prequit message to abort quit - restart it manually later if necessary
  1830. %                
  1831. centre(warning%)
  1832.              
  1833. Q             
  1834.  if no unsaved data just ignore Prequit message - let it bounce
  1835.  &502   : 
  1836. dohelp
  1837.  &400C1 : 
  1838. user_modechange
  1839.